InitMenu = function() {
    var menu = $('.menu');
    var items = $("li", menu);
    items.each(function() {
        var item = $(this);
        var tpl = "<a href=\"javascript:;\" class=\"open\">v</a>";
        if (item.children("ul").length) {
            item.children('a').css('padding-right', 0);
            item.append($(tpl));
        }
    });
    
    menu.delegate('.open', 'click', switchItem);

    function switchItem() {
        var open = $(this);
        var li = open.parent();
        li.siblings().removeClass('selected');
        $(".open", menu).not(open).removeClass('active');
        li.toggleClass('selected');
        open.toggleClass('active');
    }
}

$(document).ready(InitMenu);